from django.shortcuts import render,HttpResponse

from manager.models import *

from django.http import JsonResponse

from django.conf import settings

def fornt_index(request):
    # 获取所有要在导航上展示的 菜单
    cates = Category.objects.all().values('id', 'cate_name','seo_title','describles').order_by('-weight')
    # 获取到所有的文章内容
    articles = Article.objects.all().order_by('-id')

    menu = settings.FRONT_MENU
    data = {
        'cates': cates,
        'articles': articles,
        'menu':menu
    }

    return render(request, 'front/index.html', data)

def show(request,id):

    article = Article.objects.get(id=id)

    data = {
        'article':article,
    }

    return render(request, 'front/information.html', data)

def show_art(request,id):
    articles = Article.objects.get(category_id=id)
    data = {
        'articles':articles
    }
    return render(request,'front/listpic.html')


def list_news(request):

    menu = settings.FRONT_MENU


    # 获取所有要展示的菜单
    cates = Category.objects.all().values().order_by('-weight')

    data = {
        'cates': cates,
        'menu': menu
    }
    return render(request, 'front/cateList.html', data)

def get_cate_articles(request):
    articles = Article.objects.all()
    cates = Category.objects.all()
    data = {
        'articles':articles,
        'cates':cates
    }
    return JsonResponse(request,data)